﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Solution2DModel>" %>
<asp:Content ContentPlaceHolderID="TitleContent" runat="server">
	<%= (string)GetLocalResourceObject("Page.Title") %>
</asp:Content>
<asp:Content ContentPlaceHolderID="PageHeader" runat="server">
    <%= (string)GetLocalResourceObject("Page.Title") %>
</asp:Content>

<asp:Content ContentPlaceHolderID="MainContent" runat="server">
    <div style="position:relative; overflow:hidden;">
        <div class="problem">
            <fieldset class="fs-input-params">
                <legend><%= (string)GetLocalResourceObject("InputParams")%></legend>
                <table class="form-input-params">
                    <tr>
                        <td class="label">
                            <label for="<%= Reflector.GetPropertyName<SolutionModel>(x => x.Problem.InputParameters.N) %>">
                                <%= (string)GetLocalResourceObject("PointsCount")%>
                            </label>
                        </td>
                        <td class="value">
                            <%= Model.Problem.InputParameters.N %>
                        </td>
                        <td class="hint"><%= (string)GetLocalResourceObject("PointsCount.Hint")%></td>
                    </tr>
                    <tr>
                        <td class="label">
                            <label for="inpX1">
                                <%= (string)GetLocalResourceObject("x1") %>
                            </label>
                        </td>
                        <td class="value">
                            <%= Model.Problem.InputParameters.X1 %>
                        </td>
                    </tr>
                    <tr>
                        <td class="label">
                            <label for="inpX2">
                                <%= (string)GetLocalResourceObject("x2")%>
                            </label>
                        </td>
                        <td class="value">
                            <%= Model.Problem.InputParameters.X2 %>
                        </td>
                    </tr>
                    <tr>
                        <td class="label">
                            <label for="inpY1">
                                <%= (string)GetLocalResourceObject("y1")%>
                            </label>
                        </td>
                        <td class="value">
                            <%= Model.Problem.InputParameters.Y1 %>
                        </td>
                    </tr>
                    <tr>
                        <td class="label">
                            <label for="inpY2">
                                <%= (string)GetLocalResourceObject("y2")%>
                            </label>
                        </td>
                        <td class="value">
                            <%= Model.Problem.InputParameters.Y2 %>
                        </td>
                    </tr>
                    <tr>
                        <td class="label">
                            <label for="f">
                                <%= (string)GetLocalResourceObject("LeftPart")%>
                            </label>
                        </td>
                        <td class="value"></td>
                        <td class="hint"><%= (string)GetLocalResourceObject("LeftPart.Hint")%></td>
                    </tr>
                    <tr>
                        <td class="label">
                            <label for="inpG">
                                <%= (string)GetLocalResourceObject("ValueOnBoundary")%>
                            </label>
                        </td>
                        <td class="value"><%= Model.Problem.InputParameters.G %></td>
                        <td class="hint"><%= (string)GetLocalResourceObject("ValueOnBoundary.Hint")%></td>
                    </tr>
                    <tr>
                        <td class="label">
                            <label for="<%= Reflector.GetPropertyName<SolutionModel>(x => x.Problem.InputParameters.Epsilon) %>">
                                <%= (string)GetLocalResourceObject("Epsilon")%>
                            </label>
                        </td>
                        <td class="value"><%= Model.Problem.InputParameters.Epsilon %></td>
                        <td class="hint"><%= (string)GetLocalResourceObject("Epsilon.Hint")%></td>
                    </tr>
                    <tr>
                        <td class="label">
                            <label for="<%= Reflector.GetPropertyName<SolutionModel>(x => x.Problem.InputParameters.H) %>">
                                <%= (string)GetLocalResourceObject("H")%>
                            </label>
                        </td>
                        <td class="value"><%= Model.Problem.InputParameters.H %></td>
                        <td class="hint"><%= (string)GetLocalResourceObject("H.Hint")%></td>
                    </tr>
                    <tr>
                        <td class="label">
                            <label for="<%= Reflector.GetPropertyName<SolutionModel>(x => x.Problem.InputParameters.Alpha) %>">
                                <%= (string)GetLocalResourceObject("Alpha")%>
                            </label>
                        </td>
                        <td class="value"><%= Model.Problem.InputParameters.Alpha %></td>
                        <td class="hint"><%= (string)GetLocalResourceObject("Alpha.Hint")%></td>
                    </tr>
                </table>
            </fieldset>
            <fieldset class="fs-problem">
                <legend><%= (string)GetLocalResourceObject("Problem")%></legend>
                    <img id="imgFormula" title="<%= (string)GetLocalResourceObject("Problem")%>"
                         src="http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=\[ \left\{ \begin{array}{l l} \Delta u = f\\ u= <%= Model.Problem.InputParameters.G %> \quad \text{ on $x$=<%= Model.Problem.InputParameters.X1 %>, $y$=<%= Model.Problem.InputParameters.Y1 %>, $x$=<%= Model.Problem.InputParameters.X2 %>, $y$=<%= Model.Problem.InputParameters.Y2 %> }  \\ \end{array} \right.\]">
            </fieldset>
        </div>
    <% if(Model.State == Solution2DModel.ModelState.Solved)
       {
           %>
           <div class="solution-2d">
               <fieldset>
                   <legend><%= (string)GetLocalResourceObject("IterationsCount") %> <%= Model.Problem.Solution.IterationsCount %> (<%= Model.Problem.Solution.ExecutionTime %>)</legend>
                   <table class="header">
                        <tr>
                            <th><%= (string)GetLocalResourceObject("X") %></th>
                            <th><%= (string)GetLocalResourceObject("Y") %></th>
                            <th><%= (string)GetLocalResourceObject("U") %></th>
                            <th><%= (string)GetLocalResourceObject("U.Matlab") %></th>
                            <th class="last"><%= (string)GetLocalResourceObject("Residual") %></th>
                        </tr>
                    </table>
                    <div class="body">
                        <table>
                          <%
                              foreach (var point in Model.Problem.Solution.U)
                                {
                                    var exact = Model.Problem.ExactSolution.U.Where(x => x.X == point.X && x.Y == point.Y).SingleOrDefault();
                              %>
                              <tr>
                                <td><div><%= point.X %></div></td>
                                <td><div><%= point.Y %></div></td>
                                <td><div><%= point.Z %></div></td>
                                
                                <% if (exact != null)
                                   {
                                       var residual = exact.Z - point.Z;
                                       var colorIndex = (int)(255 * residual / 0.008);
                                       var r = colorIndex;
                                       var g = (255 - colorIndex);
                                       var color = String.Format("#ff{0:X}ff", g);
                                %>
                                <td><div><%= exact.Z.ToString() %></div></td>
                                <td style="background:<%= color %>"><div><%= (exact.Z - point.Z).ToString()%></div></td>
                                <% }
                                   else
                                   {%>
                                   <td><div>&mdash;</div></td>
                                   <td><div>&mdash;</div></td>
                                <% } %>
                              </tr>
                              <%
                                }
                               %>
                        </table>
                    </div>
                </fieldset>
           </div>
        </div>
           <%
           var value = new StringBuilder();
               var points = Model.Problem.Solution.U;

               foreach (var u in points)
               {
                   value.AppendFormat("{0}/{1}/{2}|", u.X.ToString().Replace(',','.'),
                                            u.Y.ToString().Replace(',', '.'),
                                            u.Z.ToString().Replace(',', '.'));
               }

            var exactValue = new StringBuilder();
               points = Model.Problem.ExactSolution.U;

               foreach (var u in points)
               {
                   exactValue.AppendFormat("{0}/{1}/{2}|", u.X.ToString().Replace(',', '.'),
                                            u.Y.ToString().Replace(',', '.'),
                                            u.Z.ToString().Replace(',', '.'));
               }
           %>
           <script type="text/javascript">
               function onSilverlightError(sender, args) {
                   var appSource = "";
                   if (sender != null && sender != 0) {
                       appSource = sender.getHost().Source;
                   }

                   var errorType = args.ErrorType;
                   var iErrorCode = args.ErrorCode;

                   if (errorType == "ImageError" || errorType == "MediaError") {
                       return;
                   }

                   var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

                   errMsg += "Code: " + iErrorCode + "    \n";
                   errMsg += "Category: " + errorType + "       \n";
                   errMsg += "Message: " + args.ErrorMessage + "     \n";

                   if (errorType == "ParserError") {
                       errMsg += "File: " + args.xamlFile + "     \n";
                       errMsg += "Line: " + args.lineNumber + "     \n";
                       errMsg += "Position: " + args.charPosition + "     \n";
                   }
                   else if (errorType == "RuntimeError") {
                       if (args.lineNumber != 0) {
                           errMsg += "Line: " + args.lineNumber + "     \n";
                           errMsg += "Position: " + args.charPosition + "     \n";
                       }
                       errMsg += "MethodName: " + args.methodName + "     \n";
                   }

                   throw new Error(errMsg);
               }
    </script>
    <div class="solution-graphs">
        <div class="solution-graph">
            <%= (string)GetLocalResourceObject("SolutionGraph") %>
            <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
    		  <param name="source" value="<%=ResolveClientUrl("~/ClientBin/BSU.GraduateWork.Visualizer.xap")%>"/>
    		  <param name="onError" value="onSilverlightError" />
    		  <param name="background" value="white" />
    		  <param name="initParams" value="dataSource=<%= value %>" />
    		  <param name="minRuntimeVersion" value="3.0.40624.0" />
    		  <param name="autoUpgrade" value="true" />
    		  <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
     			  <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
    		  </a>
    	    </object>
        </div>
        <div class="exact-solution-graph">
            <%= (string)GetLocalResourceObject("ExactSolutionGraph") %>
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
		  <param name="source" value="<%=ResolveClientUrl("~/ClientBin/BSU.GraduateWork.Visualizer.xap")%>"/>
		  <param name="onError" value="onSilverlightError" />
		  <param name="background" value="white" />
		  <param name="initParams" value="dataSource=<%= exactValue %>" />
		  <param name="minRuntimeVersion" value="3.0.40624.0" />
		  <param name="autoUpgrade" value="true" />
		  <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
 			  <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
		  </a>
	    </object>
        </div>
        <iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
        </div>
           <%
  } %>
</asp:Content>


